<?php

/*

Process Buy Now (auctions_buynow.php)

*/

include "global.inc.php";

$findAuction = fetch("SELECT * FROM auctions2 WHERE id = '$id' AND game = '$game'");

if ($findAuction[buy_now_price] <= 0)
{
	die(header(error("auctions.php?game=$game","That item is not available to buy now.")));
}

if ($findAuction[buy_now_price] > $points)
{
	die(header(error("auctions_bid.php?game=$game&id=$id","You do not have enough points to bid that much.")));
}

points($game, "$username", "-$findAuction[buy_now_price]");
points($game, "$findAuction[high_bidder]", "$findAuction[high_bid]");
points($game, "$findAuction[owner]", "$findAuction[buy_now_price]");

$findItem = fetch("SELECT parts,id FROM items2 WHERE item_name = '$findAuction[item_name]' AND game = '$game'");
mysql_query("INSERT INTO usersitems2 (owner,item_id,parts_left,game) VALUES ('$userid','$findItem[id]','$findItem[parts]','$game')");

mysql_query("DELETE FROM auctions2 WHERE id = '$id' AND game = '$game'");

$getAuctioner = fetch("SELECT id FROM members2 WHERE username = '$findAuction[owner]' AND game = '$game'");
systemmessage("$game", "auctions.php?game=$game","$getAuctioner[id]","Your auction of the $findAuction[item_name] has ended, via the buy now option, and you have been awarded with $findAuction[buy_now_price] $pointsVar!");
systemmessage("$game", "auctions.php?game=$game","$getAuctioner[id]","Your bid on the $findAuction[item_name] has been beaten, via the buy now option.<br>Your $findAuction[high_bid] $pointsVar have been returned to you!");

die(header(error("myitems.php?game=$game","You bought this item now, you should see it in your inventory below!")));

?>